package com.qffx.moviebase.adapter.classify;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.qffx.moviebase.R;
import com.qffx.moviebase.bean.classify.SpeacialMoreEntity;
import com.qffx.moviebase.view.classify.SpecialWebviewActivity;
import com.squareup.picasso.Picasso;

import java.util.List;

/**
 * Created by lenovo on 2017/2/9.
 */

public class SpeacialMoreAdapter extends RecyclerView.Adapter<SpeacialMoreAdapter.ViewHolder> {
    private List<SpeacialMoreEntity.TopicListBean> data;
    private LayoutInflater inflater;
    private Context context;

    public SpeacialMoreAdapter(List<SpeacialMoreEntity.TopicListBean> data, Context context) {
        this.data = data;
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = inflater.inflate(R.layout.speacial_more_iv, parent, false);
        return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
        Picasso.with(context).load(data.get(position).getImgUrl()).into(holder.iv);
        holder.tv1.setText(data.get(position).getTitle());
        holder.tv2.setText(data.get(position).getArticlesNum()+"篇/"+data.get(position).getSubscribeNum()+"人订阅");
      holder.clickUrl.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Intent intent = new Intent(context, SpecialWebviewActivity.class);
              intent.putExtra("url",data.get(position).getShareInfo().getUrl());
              context.startActivity(intent);


          }
      });

    }

    @Override
    public int getItemCount() {
        return data.size();
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView iv;
        private TextView tv1, tv2;
        private LinearLayout clickUrl;

        public ViewHolder(View itemView) {
            super(itemView);
            iv= (ImageView) itemView.findViewById(R.id.speacial_more_iv);
            tv1= (TextView) itemView.findViewById(R.id.speacial_more_title);
            tv2= (TextView) itemView.findViewById(R.id.speacial_more_num);
            clickUrl= (LinearLayout) itemView.findViewById(R.id.speacial_more_click);
        }
    }
}
